
//import assembler.TranslateProcess;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URL;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JTextField;
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.undo.UndoManager;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

//import assembler.*;
//import Emulator.*;

/**
 * Title:  Group.java
 * Description:  This class offers a basic GUI
 * Copyright:    Copyright (c) 2009
 * @author WANG Jiechao
 * @version 1.0
 */
public class Group extends JFrame implements ActionListener, FocusListener, ChangeListener{

	private static final long serialVersionUID = 1L;
	static Group localGroup; //the biggest class
    JMenuBar menuBar, menuBar_EAST, menuBar_CENTER; //one total menu bar and two sub menu bars
    JMenu edit, file, compile; //two menus
    Style style = new Style();//create "style" menu from class "Style";  //another menu
    View view;  //another menu
    JPanel center, west, south;  //build panels in GUI
    //JPanel south1, south2, south3;  //three panels in south
    tabs text2, text3, text4, text5, text6, text7;  //classes for JPanel
    JToolBar toolBar; //build tool bar in GUI
    JButton []button = new JButton [9];  //build buttons in tool bar
    JCheckBoxMenuItem cbMenuItem1, cbMenuItem2, cbMenuItem3, cbMenuItem4;
    ButtonGroup localButtonGroup;  //set button in the same group
    int trueOrNot;
    int westAppeared=1;
    static JClosableTabbedPane text1;  //class for JPanel
    EditorAction editor;			//Declare Editor that extends JMenu.
    int a, b, c, d, e, f, g, h, i, j;  //count to check which panels are visible
    JMenuItem [] menuItem = new JMenuItem [5];
    JMenuItem compileItem1;
    JTextField textField;
    boolean firstClick=true; 
    JFrame frame_out;
    JInternalFrame internalFrame;
    JDesktopPane desktopPane; //set desktopPane for internalFrame
    SearchBar search;
    JMenuItem[] editItems=null;
    UndoManager undoListener;//Undo and redo listener
    JMenuItem[] popItem=null;//popmenu
    PopupListener PL=new PopupListener();//mouse listener of popup menu
    JPopupMenu popup=null;//popup menu
    static Tree tree=new Tree();
    int tabNumber=3;
    JTabbedPane consoleTabbedPane = new JTabbedPane();
    static String s;
    Configure configure=new Configure();
    UndoAndRedo undoAndRedo = new UndoAndRedo();
    /**
     * This constructor set the GUI layout and its size.
     */
    public Group() {
        super("GROUP");
        setDefaultCloseOperation(3);
        //setSize(1280, 778);
        setSize(800,600);
        setLayout(new BorderLayout());
        //text1 = new JTextArea(20, 30);
        text1 = new JClosableTabbedPane();
        text2 = new tabs();
        text3 = new tabs();
        text4 = new tabs();
        text5 = new tabs();
        text6 = new tabs();
        //text7 = new JTextArea(5, 10);
        text7 = new tabs();
        search = new SearchBar();
        search.myAction(((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());//pass the currently selected text to SearchBar class
        
        
        this.setJMenuBar(createMenuBar());
        
        this.add(createToolBar(), BorderLayout.NORTH);
        
        JSplitPane innerSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,createWest(), createCenter());
        innerSplit.setDividerLocation(250);

        JSplitPane outerSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT,innerSplit,createSouth());
        outerSplit.setDividerLocation(500);
        
        this.add(outerSplit, BorderLayout.CENTER);
        
        undoListener = new UndoManager();
        ((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).getTextPane().getDocument().addUndoableEditListener(undoListener);
        ((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).getTextPane().addMouseListener(PL);//add popmenu listener
        
        try{
            //localJFrame.setDefaultLookAndFeelDecorated(false);
           UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
           SwingUtilities.updateComponentTreeUI(this);
        }catch (UnsupportedLookAndFeelException localUnsupportedLookAndFeelException) {
           System.err.println("Unsupported LookAndFeel: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        }catch (ClassNotFoundException localClassNotFoundException) {
           System.err.println("LookAndFeel class not found: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        }catch (InstantiationException localInstantiationException) {
           System.err.println("Could not load LookAndFeel: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        }catch (IllegalAccessException localIllegalAccessException) {
           System.err.println("Cannot use LookAndFeel: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
         }      

        /*  Metal "javax.swing.plaf.metal.MetalLookAndFeel"
            Motif "com.sun.java.swing.plaf.motif.MotifLookAndFeel"
            nimbus "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"
            Windows "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
        */   
        //this.pack();
        undoAndRedo.setTextPane(((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
        text1.addChangeListener(this);
        this.setVisible(true);

    }

    /**
     * called when a node in the tree has been double clicked
     * I make it static so that I can access it without making an instance of Group
     * @throws IOException 
     */   
    public static void openFile() throws IOException{
    	tree.openFile(text1);
    }
    
    /**
     * a method to create menu bar
     */
    public JMenuBar createMenuBar() {

        menuBar = new JMenuBar();                                                //create a menu bar

        file = new JMenu("File");//create "file" menu and items in it        

        String [] itemNames = {"New","Open","Save","Save as","Close"};
        
        for(int i=0;i<itemNames.length;i++){
        	menuItem[i]=new JMenuItem(itemNames[i]);
        	file.add(menuItem[i]);
        	menuItem[i].addActionListener(this);        	
        }        
        
        menuItem[0].setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_N, ActionEvent.CTRL_MASK));
        menuItem[1].setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        menuItem[2].setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        menuItem[3].setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_B, ActionEvent.CTRL_MASK));
        menuItem[4].setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_D, ActionEvent.CTRL_MASK));
        

        //Add items of "Edit" menu;
        String[] ItemName={"Undo","Redo","",
				"Copy","Cut","Paste","Delete","",
				"Select All","","Find/Replace"};
        edit=new JMenu("Edit");
        editor=new EditorAction();
        popup=new JPopupMenu();
        editItems=new JMenuItem[ItemName.length];
        popItem=new JMenuItem[ItemName.length];
        for(;i<ItemName.length;i++){//if "", add separator
        	if("".equals(ItemName[i])){
        		edit.addSeparator();
        		popup.addSeparator();
        	}else{
        		editItems[i]=new JMenuItem(ItemName[i]);
        		popItem[i]=new JMenuItem(ItemName[i]);
        		edit.add(editItems[i]);
        		popup.add(popItem[i]);
        		editItems[i].addActionListener(this); 
        		popItem[i].addActionListener(this);
        		setAccele(editItems[i]);
        		setAccele(popItem[i]);
        	}	
        }
        add(popup);
        
        compile = new JMenu("Compile");
        compileItem1 = new JMenuItem("Compile");
        compileItem1.addActionListener(this);
        compile.add(compileItem1);
        
        view = new View();//create "view" menu from class "View"        
        
        //add all the created menus
        menuBar.add(file);
        menuBar.add(edit);
        menuBar.add(compile);
        menuBar.add(style);
        menuBar.add(view);
        menuBar.add(configure.getConfigureMenu());
        
        configure.getColorItem().addActionListener(this);

        //add action listeners to the items
        view.getRbMenuItem1().addActionListener(this);
        view.getRbMenuItem2().addActionListener(this);
        view.getRbMenuItem3().addActionListener(this);
        view.getRbMenuItem4().addActionListener(this);
        view.getRbMenuItem5().addActionListener(this);
        view.getRbMenuItem6().addActionListener(this);
        view.getRbMenuItem7().addActionListener(this);
        view.getRbMenuItem8().addActionListener(this);
        view.getRbMenuItem9().addActionListener(this);
        view.getRbMenuItem10().addActionListener(this);

        style.getCbMenuItem1().addActionListener(this);
        style.getCbMenuItem2().addActionListener(this);
        style.getCbMenuItem3().addActionListener(this);
        style.getCbMenuItem4().addActionListener(this);

        return this.menuBar;
    }
    
    //added and shown the keyboard controllers for edit functions.
    public void setAccele(JMenuItem i){
        if("Undo".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,InputEvent.CTRL_MASK));
        }else if("Redo".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y,InputEvent.CTRL_MASK));
        }else if("Copy".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
        }else if("Cut".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));
        }else if("Paste".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));
        }else if("Select All".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
        }else if("Find/Replace".equals(i.getText())){
            i.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,InputEvent.CTRL_MASK));
        }
    }

    /**
     * a method to create tool bar
     */
    public JToolBar createToolBar() {
        toolBar = new JToolBar();
        String [] imageName = {"new.png","open.png","save.png","paste.png",null,"home.png",
        		"external.png","internal.png","close.png"};
        String [] tips = {"Your own hint1","Your own hint2","Your own hint3","Open East",
        		null,"Normalize","Externalize","Internalize","invisualize"};
        
        toolBar.addSeparator();//Add two separators                                                  
        toolBar.addSeparator();
        
        for (int i=0;i<=8;i++){
        	if (i!=4){
        		button[i] = new JButton (new ImageIcon(imageName[i]));
        		toolBar.add(button[i]);//add buttons to tool bar
        		button[i].addActionListener(this);
        		button[i].setToolTipText(tips[i]);//set tool tip for each button. They will appear when the mouse stays on any one of the buttons.
        	}
        	else{
        		toolBar.addSeparator();//Add two separators                                                  
                toolBar.addSeparator();
        		textField = search.getSearchBar();//get the textField for searching from SearchBar class
                toolBar.add(textField);//for getting 
                textField.addFocusListener(this);
        		button[i] = search.getSearchButton();//get the button for searching from SearchBar class
        		toolBar.add(button[i]);//add buttons to tool bar
        		button[i].addActionListener(this);        		
        	}
        } 
        
        toolBar.setFloatable(false);//set tool bar as unfloatable
        return toolBar;
    }

    /**
     * a method to create a panel in center
     */
    public JPanel createCenter() {
        center = new JPanel(new BorderLayout());
        center.add(text1,BorderLayout.CENTER);
        center.setVisible(true);
        return center;
    }

    /**
     * a method to create a panel in east and add three panels in this panel
     */
    public JPanel createWest() {
        west = tree.getTreePanel();
        west.setPreferredSize(new Dimension(270, 150));
        west.setVisible(true);
        return west;
    }

    /**
     * a method to create a panel in south and add three panels in this panel
     */
    public JPanel createSouth() {
    	//CloseTabIcon closeIcon=new CloseTabIcon(new Icon());
        south = new JPanel();
        south.setLayout(new BorderLayout());
        south.setPreferredSize(new Dimension(200, 150));

        
/*        JTextArea consoleTextArea1=new JTextArea();
        consoleTextArea1.setEditable(false);
        consoleTabbedPane.addTab("tab", consoleTextArea1);
        
        JTextArea consoleTextArea2=new JTextArea();
        consoleTextArea2.setEditable(false);
        consoleTabbedPane.addTab("tab", consoleTextArea2);
        
        JTextArea consoleTextArea3=new JTextArea();
        consoleTextArea3.setEditable(false);
        consoleTabbedPane.addTab("tab", consoleTextArea3);*/
        for (int i = 0; i < tabNumber; i++) {
            String title = "Tab";
            consoleTabbedPane.add(title, new JScrollPane(new JTextArea()));
            initTabComponent(i);
        }
        
        south.add(consoleTabbedPane);
        return south;
    }
    
    private void initTabComponent(int i) {
    	consoleTabbedPane.setTabComponentAt(i,
                 new ButtonTabComponent("TabComponent " + i, consoleTabbedPane));
    }   

    /**
     * a method to create an ImageIcon
     *
     * @param paramString the name of the ImageIcon
     */
    protected static ImageIcon createImageIcon(String paramString) //Handle image icon exception
    {
        URL localURL = Group.class.getResource(paramString);
        if (localURL != null) {
            return new ImageIcon(localURL);
        }

        System.err.println("Couldn't find file: " + paramString);
        return null;
    }
    
    public static void goTo(Container container, String string1, String title1, String string2, String title2){
    	//the following is actually the implementation of "goto"      
        loop:for (int i=0;i<=0;i--){
        	s = (String)JOptionPane.showInputDialog(
        		container,
                string1,
                title1,
                JOptionPane.PLAIN_MESSAGE,
                null,
                null,
                "");
        	if (text1.getTabCount()>=1 && s.equals("")){
        	JOptionPane.showMessageDialog(container,
        			string2,
        			title2,
            	    JOptionPane.ERROR_MESSAGE);
        	continue loop;
        	}
        	else
        		break;
        }    	
    }

    /**
     * define actions to perform when a mouse clicks
     *
     * @param paramActionEvent the action event
     */
    public void actionPerformed(ActionEvent paramActionEvent) //Define the actions performed after events
    {           
        
        if (paramActionEvent.getSource() == view.getRbMenuItem1()) {
            a++;                                                        //Make the tool bar disappear upon a click and
            if (a % 2 == 0) //reappear upon another click
            {
                toolBar.setVisible(true);
            } else {
                toolBar.setVisible(false);
            }
        }
        if (paramActionEvent.getSource() == view.getRbMenuItem2()) {
            b++;                                                       //Make the split pane disappear upon a click and
            if (b % 2 == 1) //reappear upon another click
            {
                center.setVisible(false);
            } else {
                center.setVisible(true);
            }
        }
        if (paramActionEvent.getSource() == view.getRbMenuItem3()) {
            c++;                                                       //Make the split pane disappear upon a click and 
            if (c % 2 == 0) //reappear upon another click
            {
                west.setVisible(false);
            } else {
                west.setVisible(true);
            }
        }

        if (paramActionEvent.getSource() == view.getRbMenuItem7()) {
            g++;                                                       //Make the split pane disappear upon a click and 
            if (g % 2 == 1) //reappear upon another click
            {
                south.setVisible(false);
            } else {
                south.setVisible(true);
            }
        } 

        if (paramActionEvent.getSource() == style.getCbMenuItem1()) {                       //Provide users with opportunity to select the look and feel they
            style.setStyle(localGroup, 1);        	
        }

        if (paramActionEvent.getSource() == style.getCbMenuItem2()) {
        	style.setStyle(localGroup, 2); 
        }

        if (paramActionEvent.getSource() == style.getCbMenuItem3()) {
        	style.setStyle(localGroup, 3); 
        }

        if (paramActionEvent.getSource() == style.getCbMenuItem4()) {
        	style.setStyle(localGroup, 4); 
        }

        if (paramActionEvent.getSource() == button[3]) {
            this.westAppeared += 1;                                                       //Make the split pane disappear upon a click and
            if (this.westAppeared % 2 == 1) {                                              //reappear upon another click

                west.setVisible(true);
                //east.updateUI();
            } else {
                west.setVisible(false);
                //east.updateUI();
            }
        }
        

     /*   if (paramActionEvent.getSource() == compileItem1) {
            TestUI test = new TestUI();
            TranslateProcess d = new TranslateProcess(text1.my.getText());
            d.process();
            test.test.ram.memory= d.tr.getOutString();
            test.setVisible(true);
        }*/
        if(text1.getTabCount()>=1 && (Panel2A) text1.getComponentAt(text1.getSelectedIndex())!=null){
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane().getDocument().addUndoableEditListener(undoListener);
        }
        
        if (paramActionEvent.getSource() == menuItem[0]) {
        	
        	Group.goTo(localGroup,"Type in the name of the new file","New file","Please enter the name","ERROR");
        	if (s!= null){
        		Panel2A file = new Panel2A();
        		text1.addTab(s+" ", file);
        	}
        }
        if (paramActionEvent.getSource() == menuItem[1]) {
        	text1.addTab(null, new Panel2A());
        	System.out.println(text1.getTabCount());
        	((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).listenuper=1;
        	((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).fileAction(1);
        	if(((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).nothingReadIn){
        		text1.remove(text1.getTabCount()-1);
        		
        	}
        	String tabTitle = ((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).filename;
            text1.setTitleAt((text1.getTabCount()-1),tabTitle);
            ((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).getTextPane().getDocument().addUndoableEditListener(undoListener);
            ((Panel2A) text1.getComponentAt(text1.getTabCount()-1)).getTextPane().addMouseListener(PL);//add popmenu listener
        }
        if (paramActionEvent.getSource() == menuItem[2]) {
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).listenuper=2;
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).fileAction(2);
        }
        if (paramActionEvent.getSource() == menuItem[3]) {
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).listenuper=3;
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).fileAction(3);
        }
        if (paramActionEvent.getSource() == menuItem[4]) {
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).listenuper=4;
        	((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).fileAction(4);
        }
        
    //To provide users with convenient shift from normal mode to other modes	  
    if (paramActionEvent.getSource() == button[5]) { //normal mode
	  
	  if(i!=0){
		//center.add(text1, "Center");
		center.add(text1);	
		center.updateUI();
		text1.setVisible(true);
	  }	 
	  	 	                                          	
	  if(i==1){
	  	frame_out.setVisible(false);		
	  }
	
	  if(i==2){	
	  	desktopPane.setVisible(false);  	
	  }
			
	  i=0; //into state 0
    }

    if (paramActionEvent.getSource() == button[6]) { //external mode

      text1.setVisible(true);    	
      if(i!=1|i==3){     
      	frame_out = new JFrame("External Frame");
		frame_out.setLocation( 50,100);//set frame_out's local
		frame_out.setSize(750, 400);  //set frame_out's size 
     	frame_out.setVisible(true);

		frame_out.add(text1,"Center");
		//text1.setVisible(true);
        center.updateUI();
      }	
      	
	  if(i==0){		
	  }	
	
	  if(i==1){
	    frame_out.setVisible(true);			
	  }		  	
	  	
      if(i==2){      
		desktopPane.setVisible(false);
	  }
		
      i=1; //into state 1
    }

    if (paramActionEvent.getSource() == button[7]) { //internal mode
    	
      text1.setVisible(true);
	  if(i!=2|i==3){
	  	desktopPane = new JDesktopPane(); //set desktopPane for internalFrame
		internalFrame = new JInternalFrame("Internal Frame", true, true, true, true);  
		
	    internalFrame.setLocation(20, 20); //set internalFrame's local
        internalFrame.setSize(750, 250); //set internalFrame's size
        
        internalFrame.setVisible(true);
		internalFrame.add(text1,"Center");	
		center.add(desktopPane);
		desktopPane.add(internalFrame);		
		center.updateUI();					
	  }

	  if(i==1){		
		frame_out.setVisible(false);
	  }
	  
	  if(i==2){	
	  	//refresh internalFrame
        desktopPane.remove(internalFrame);
        desktopPane.add(internalFrame);
        internalFrame.setVisible(true);
	  }
		
	  i=2; //into state 2
    }

    if (paramActionEvent.getSource() == button[8]) { //close mode
	  if(i==0)
		text1.setVisible(false);
	  if(i==1){
		frame_out.setVisible(false);
		//text1.setVisible(false);
	  }
	  if(i==2){
		desktopPane.setVisible(false);
		//text1.setVisible(false);
	  }
	  if(i==3)
		text1.setVisible(false);
		
	  i=3; //into state 3
    }
    
    if (paramActionEvent.getSource() == configure.getColorItem()) {
    	configure.changeColor(localGroup, ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
    if (paramActionEvent.getSource() == button[4]) { //click to search
    	search.isFirst=false;
    	search.myAction(((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());//pass the currently selected text to SearchBar class    
    }    

    if (paramActionEvent.getSource()==editItems[0]) { 
    	//undoAndRedo.setTextPane(((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    	undoAndRedo.myAction(paramActionEvent, 1);
    }
    
    if (paramActionEvent.getSource()==editItems[1]) { 
    	//undoAndRedo.setTextPane(((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    	undoAndRedo.myAction(paramActionEvent, 2);
    }
    
    if (paramActionEvent.getActionCommand()=="Copy") { //Click to Copy
    //	System.out.println(Item[3].getText());
    	editor.myAction(editItems[3], ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
    if (paramActionEvent.getActionCommand()=="Cut") { //Click to Cut
    //	System.out.println(Item[4].getText());
    	editor.myAction(editItems[4], ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
    if (paramActionEvent.getActionCommand()=="Paste") { //Click to Paste
    //	System.out.println(Item[5].getText());
    	editor.myAction(editItems[5], ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
    if (paramActionEvent.getActionCommand()=="Delete") {  //Click to Delete
    //	System.out.println(Item[6].getText());
    	editor.myAction(editItems[6], ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
    if (paramActionEvent.getActionCommand()=="Select All") {  //click to select all
    //	System.out.println(Item[8].getText());
    	editor.myAction(editItems[8], ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
    if (paramActionEvent.getActionCommand()=="Find/Replace") {  //Click to find and replace
    //	System.out.println(Item[10].getText());
    	editor.myAction(editItems[10], ((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());
    }
    
  }
    public void focusGained(FocusEvent paramFocusEvent)                             //Action perform based on the following rules:
    {                                                                               //First click clears the default words
    if (paramFocusEvent.getSource() == this.textField & firstClick) {        //Second and following click do not clear anything
      this.textField.setText("");                                        
      this.firstClick = search.firstClick = false;  
    }
  }
  
    public void focusLost(FocusEvent paramFocusEvent) {
    }
    
	public void stateChanged(ChangeEvent e) {
		undoAndRedo.setTextPane(((Panel2A) text1.getComponentAt(text1.getSelectedIndex())).getTextPane());	
		System.out.println(text1.getSelectedIndex());
		//System.out.print("grftg");
	}
  
    class PopupListener extends MouseAdapter {
  	    public void mousePressed(MouseEvent e) {
  		if(e.getButton() == MouseEvent.BUTTON3){
      	    popup.show(((JTextPane)e.getComponent()), e.getX(), e.getY());}
      	}
    }
  
  

    /**
     * the main method to set a basic layout of this GUI
     */
    public static void main(String[] paramArrayOfString) {
        localGroup = new Group();
    }
}
